import React, { Component } from 'react'
import Layout from './pages/Layout'
import Login from './pages/Login'
import { Router, Route, Switch } from 'react-router-dom'
import AuthRoute from 'components/AuthRoutr'
import history from 'utils/history'
import Test from './pages/Test'
export default class App extends Component {
  render() {
    return (
      <div>
        <Router history={history}>
          <Switch>
            {/* 书写顺序从上往下匹配，需先匹配登录页 */}
            {/* Test测试路由 */}
            <Route path='/test' component={Test}></Route>
            <Route path='/login' component={Login}></Route>
            {/* 嵌套路由的父路由不能写精确匹配 */}
            {/* <Route path='/' component={Layout}></Route> */}
            {/* render鉴权路由 render用法 {...props}解构传递 */}
            {/* <Route
              path='/'
              render={(props) => {
                const token = localStorage.getItem('system-token')
                if (token) {
                  return <Layout {...props} />
                } else {
                  // 路由信息存到state里面去
                  return <Redirect to={{ pathname: '/login', state: { form: props.history.pathname } }} />
                }
              }}
            /> */}
            <AuthRoute path='/' component={Layout}></AuthRoute>
          </Switch>
        </Router>
      </div>
    )
  }
}
